﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace RohonTool.Init
{
    class MainTool
    {
        private Thread threadMonitorInput;
        private Thread mumayi;
        //private Thread _5diary;
        //  private Thread joke;
        private string title;
        public MainTool(string title)
        {
            this.title = title;
        }

        public void Show()
        {
            Console.Title = title;
            Win32Helper.ConsoleWin32Helper win32 = new Win32Helper.ConsoleWin32Helper(title);
            win32.ShowNotifyIcon();
            win32.DisableCloseButton(Console.Title);

            threadMonitorInput = new Thread(new ThreadStart(Run));
            threadMonitorInput.Start();

            SpiderHelper.EnterPoint sina = new SpiderHelper.EnterPoint();
            mumayi = new Thread(new ThreadStart(sina.Start));
            mumayi.Start();

            //HttpVistor.MMOnly.MMVisitor mvisitor = new HttpVistor.MMOnly.MMVisitor();
            //mumayi = new Thread(new ThreadStart(mvisitor.Start));
            //mumayi.Start();

            //HttpVistor._5diary.Visiter visiter = new HttpVistor._5diary.Visiter();
            //_5diary = new Thread(new ThreadStart(visiter.GetPics));
            //_5diary.Start();

            //HttpVistor.Joke.JokeJi jvisiter = new HttpVistor.Joke.JokeJi();
            //joke = new Thread(new ThreadStart(jvisiter.Read));
            //joke.Start();

            while (true)
            {
                Application.DoEvents();
                if (isStop)
                {
                    break;
                }
            }
        }

        public static bool isStop = false;
        public void Run()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input.Equals("quit"))
                {
                    RohonOutPut.OutPut.Report.couldOutput = true;
                    isStop = true;
                    mumayi.Abort();
                    //_5diary.Abort();
                    //joke.Abort();
                    threadMonitorInput.Abort();
                    Thread.CurrentThread.Abort();
                }
                else if (input.Equals(""))
                {
                    RohonOutPut.OutPut.Report.couldOutput = false;
                }
            }
        }
    }
}
